package com.yn.xgame.gamecenter;

import com.yn.xgame.CommonConfig;
import com.yn.xgame.CommonMqMessageHandler;
import com.yn.xgame.MQClient;
import com.yn.xgame.ZkClient;
import com.yn.xgame.game.GameCenterManager;
import com.yn.xgame.game.GameCenterManagerParser;

/**
 * GameCenterApp
 * 大厅服务器，可管理多个子游戏大厅。
 * Created by wangboo on 17/7/15.
 */
public class GameCenterApp {

    static CommonConfig config;
    static ZkClient zkClient;
    static MQClient mqClient;
    static GameCenterServer centerServer;

    public static void main(String[] args) throws Exception {
        String cfgFile = "center1.cfg";
        if (args.length > 1) cfgFile = args[0];
        config = new CommonConfig("center", cfgFile);
        GameCenterManager gcMgr = GameCenterManagerParser.parse("center" + config.getId() + ".xml");
        centerServer = new GameCenterServer(gcMgr);
        zkClient = new ZkClient();
        zkClient.connect(config.getZkAddress(), null);
        CommonMqMessageHandler handler = new CommonMqMessageHandler(centerServer);
        String topic = "center" + config.getId();
        mqClient = new MQClient(config.getKafkaProp(), handler, config.getMqGroup(), topic);
        mqClient.start();
        gcMgr.reportToZK(zkClient);
        centerServer.startup();
        centerServer.join();
    }

}
